package com.xjrsoft.module.taskSchedule.controller;


import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.tool.utils.StringPool;
import com.xjrsoft.module.taskSchedule.dto.QueryTsLogPageListDto;
import com.xjrsoft.module.taskSchedule.service.IXjrTsLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 * 任务执行日志表 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-11-10
 */
@RestController
@AllArgsConstructor
@RequestMapping("/task-scheduling-log")
@Api(value = "/task-scheduling", tags = "任务调度日志模块")
public class XjrTsLogController {

    private IXjrTsLogService logService;

    @GetMapping
    @ApiOperation(value = "获取任务日志列表 分页")
    public Response getPageList(QueryTsLogPageListDto dto) {
        return Response.ok(logService.getPageList(dto));
    }

    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除任务日志")
    public Response deleteTaskLog(@PathVariable String ids) {
        String[] idArray = StringUtils.split(ids, StringPool.COMMA);
        boolean isSuccess = false;
        if (idArray.length == 1) {
            isSuccess = logService.removeById(ids);
        } else {
            isSuccess = logService.removeByIds(Arrays.asList(idArray));
        }
        return Response.status(isSuccess);
    }
}
